package com.smartwebx.ha.web.gis.module.screen;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class PinLvScreen extends BasicScreen {
	@Autowired
	private HttpServletRequest request;

	private String getPinLvImage(String sData, String cs, String cv,
			String title, String id, String jsz, String path)
			throws IOException {
		ComThread.InitSTA();
		ActiveXComponent isoline = new ActiveXComponent("HFre.Application");
		Dispatch msg = isoline.getObject();
		Variant v = Dispatch.call(msg, "getPLChart", new Variant(title),
				new Variant(sData), new Variant(cs), new Variant(cv),
				new Variant(765), new Variant(500), new Variant(path),
				new Variant(jsz));
		String r = v.toString().replace('=', ':').replace('\r', '@')
				.replace('\n', '!').replace('\\', '#');
		ComThread.Release();
		return r;
	}

	public String drawPl(String data, String cs, String cv, String title,
			String id, String jsz) throws IOException {
		String pngPath = "plImg/" + id + ".png";
		String realPath = request.getSession().getServletContext()
				.getRealPath("gis_js/" + pngPath);
		PinLvScreen pinLv = new PinLvScreen();
		String blb = pinLv
				.getPinLvImage(data, cs, cv, title, id, jsz, realPath);
		blb = blb.replace('\\', '#');
		System.out.println(blb);
		return pngPath;
	}

	public static void main(String[] args) throws IOException {
		System.out.println(System.getProperty("java.library.path"));
		PinLvScreen pinLv = new PinLvScreen();
		String blb = pinLv
				.getPinLvImage(
						"389.7 340.6 338.2 324.1 323.9 319.6 307.5 303.3 301.3 300.0 292.8 284.5 279.4 278.5 273.3 272.6 271.0 260.1 258.2 256.8 256.3 253.0 238.6 234.2 227.6 224.0 216.8 212.0 192.2 181.1 177.6 176.3 170.7 169.0 166.9 164.7 164.0 162.7 162.4 160.4 152.3 142.6 137.3 128.4 127.4 126.1 105.7 0.0",
						"0.5", "3.1", "老鸦坝历年最大15天降雨频率曲线", "pinlv", "0.0",
						"d:/pl2.png");
		blb = blb.replace('\\', '#');
		System.out.println(blb);
	}
}